$(function(){
	var namesearch=$(".name_btn");
	var bookname=$(".bookname_search");
	var page=$("#now");
	namesearch.click(function(){
		$.ajax({
			type:"get",
			data:{queryType:0,page:page.html(),book_name:bookname.val()},
			dataType:"json",
			url:"BookQueryServlet",
			success:function(msg){
				$(".firstLine.none").removeClass("none");
				$(".toseemore.none").removeClass("none");
				if(msg==null||msg.length==0){
					alert("数据库查不到");
				}
				else{
					var pNum=page.html();
					page.html(pNum+1);
					for(var i=0;i<msg.length;i++){
						var tr=$("tr:nth-child("+(i+2)+")");
						tr.removeClass("none");
						$("tr:nth-child("+(i+2)+") #book_id").html(msg[i].book_id);
						$("tr:nth-child("+(i+2)+") #book_code").html(msg[i].book_code);
						$("tr:nth-child("+(i+2)+") #book_name").html(msg[i].book_name);
						$("tr:nth-child("+(i+2)+") #writer").html(msg[i].writer);
						$("tr:nth-child("+(i+2)+") #publisher").html(msg[i].publisher);
						$("tr:nth-child("+(i+2)+") #date").html(msg[i].publish_date);
						$("tr:nth-child("+(i+2)+") #type").html(msg[i].type);
						$("tr:nth-child("+(i+2)+") #libName").html(msg[i].library_name);
						$("tr:nth-child("+(i+2)+") #isTeacher").html(msg[i].only_teach);
						$("tr:nth-child("+(i+2)+") #onShelf").html(msg[i].book_on_shelf);
						$("tr:nth-child("+(i+2)+") #location").html(msg[i].location);
						//$("tr:nth-child("+(i+2)+") #order").html(msg[i].);
					}
				}
			}
		});
	});
	
	var idsearch=$(".id_btn");
	var bookid=$(".bookid_search");
	idsearch.click(function(){
		$.ajax({
			type:"get",
			data:{queryType:1,page:page.html(),book_id:bookid.val()},
			dataType:"json",
			url:"BookQueryServlet",
			success:function(msg){
				$(".firstLine.none").removeClass("none");
				$(".toseemore.none").removeClass("none");
				alert(msg.length);
				if(msg==null||msg.length==0){
					alert("数据库查不到");
				}
				else{
					var pNum=page.html();
					page.html(pNum+1);
					for(var i=0;i<msg.length;i++){
						var tr=$("tr:nth-child("+(i+2)+")");
						tr.removeClass("none");
						$("tr:nth-child("+(i+2)+") #book_id").html(msg[i].book_id);
						$("tr:nth-child("+(i+2)+") #book_code").html(msg[i].book_code);
						$("tr:nth-child("+(i+2)+") #book_name").html(msg[i].book_name);
						$("tr:nth-child("+(i+2)+") #writer").html(msg[i].writer);
						$("tr:nth-child("+(i+2)+") #publisher").html(msg[i].publisher);
						$("tr:nth-child("+(i+2)+") #date").html(msg[i].publish_date);
						$("tr:nth-child("+(i+2)+") #type").html(msg[i].type);
						$("tr:nth-child("+(i+2)+") #libName").html(msg[i].library_name);
						$("tr:nth-child("+(i+2)+") #isTeacher").html(msg[i].only_teach);
						$("tr:nth-child("+(i+2)+") #onShelf").html(msg[i].book_on_shelf);
						$("tr:nth-child("+(i+2)+") #location").html(msg[i].location);
						//$("tr:nth-child("+(i+2)+") #order").html(msg[i].);
					}
				}
			}
		});
	});
	
	
	
	var typesearch=$(".type_btn");
	var booktype=$(".booktype_search");
	typesearch.click(function(){
		$.ajax({
			type:"get",
			data:{queryType:2,page:page.html(),book_type:booktype.val()},
			dataType:"json",
			url:"BookQueryServlet",
			success:function(msg){
				$(".firstLine.none").removeClass("none");
				$(".toseemore.none").removeClass("none");
				alert(msg.length);
				if(msg==null||msg.length==0){
					alert("数据库查不到");
				}
				else{
					var pNum=page.html();
					page.html(pNum+1);
					for(var i=0;i<msg.length;i++){
						var tr=$("tr:nth-child("+(i+2)+")");
						tr.removeClass("none");
						$("tr:nth-child("+(i+2)+") #book_id").html(msg[i].book_id);
						$("tr:nth-child("+(i+2)+") #book_code").html(msg[i].book_code);
						$("tr:nth-child("+(i+2)+") #book_name").html(msg[i].book_name);
						$("tr:nth-child("+(i+2)+") #writer").html(msg[i].writer);
						$("tr:nth-child("+(i+2)+") #publisher").html(msg[i].publisher);
						$("tr:nth-child("+(i+2)+") #date").html(msg[i].publish_date);
						$("tr:nth-child("+(i+2)+") #type").html(msg[i].type);
						$("tr:nth-child("+(i+2)+") #libName").html(msg[i].library_name);
						$("tr:nth-child("+(i+2)+") #isTeacher").html(msg[i].only_teach);
						$("tr:nth-child("+(i+2)+") #onShelf").html(msg[i].book_on_shelf);
						$("tr:nth-child("+(i+2)+") #location").html(msg[i].location);
						//$("tr:nth-child("+(i+2)+") #order").html(msg[i].);
					}
				}
			}
		});
	});
	
});